<link href="__PUBLICURL__/ztree/css/zTreeStyle.css" rel="stylesheet" type="text/css" />
<script src="__PUBLICURL__/ztree/jquery.ztree.js"></script>
<script src="__PUBLICURL__/ztree/jquery.ztree.exhide.js"></script>
<script src="__PUBLICURL__/ztree/jquery.ztree.excheck.js"></script>
<script>
var zTree;
var setting = {
    view: {
		nameIsHTML: true
    },
	check: {
            enable: true
    },
    data: {
		key: {
			title:"title"
		},
		
        simpleData: {
            enable: true,
            idKey: "cid",
            pIdKey: "pid",
            rootPId: ""
        }
    }
};
var zNodes = [
 <?php echo $class_tree; ?>
];
$(document).ready(function() {
    var t = $("#tree");
    t = $.fn.zTree.init(t, setting, zNodes);
});
</script>
<div class="page_function">
  <div class="info">
    <h3>管理组{$action_name}</h3>
    <small>使用以下功能进行管理组{$action_name}操作</small> 
  </div>
</div>
<div class="tab" id="tab"> 
<a class="selected" href="#tab1">基本信息</a>
<a href="#tab2">栏目内容权限</a>
<a href="#tab3">功能权限</a>
<?php if(model('user_group')->model_power('user_group','visit')){ ?>
 <a  href="javascript:menuload('__URL__')">返回管理组列表</a>
 <?php } ?>
 </div>
<div class="page_form">
<form action="__URL__/{$action}_save/time-<?php echo time() ?>-ajax-true" method="post" id="form">
<div class="page_table form_table" id="tab1">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
          <td width="100" align="right">管理组名称</td>
          <td width="300"><input name="name" type="text" class="text_value" id="name" value="{$info.name}" reg="\S" msg="管理组名称不能为空" /></td>
          <td><!--if:{$info['keep']==1}-->保留用户组不受权限控制<!--{/if}--></td>
        </tr>
        <!--if:{$user['grade']==1}-->
        <tr>
          <td width="100" align="right">管理等级</td>
          <td width="300">
          <select name="grade" id="grade">
          	<option value="1" <!--if:{$info['grade']==1}--> selected="selected" <!--{/if}--> >一级管理组</option>
            <option value="2" <!--if:{$info['grade']==2}--> selected="selected" <!--{/if}--> >二级管理组</option>
            <option value="3" <!--if:{$info['grade']==3}--> selected="selected" <!--{/if}--> >三级管理组</option>
          </select>
          </td>
          <td>低级别将看不到高级别的管理组与所属用户(只有级别等于一级的用户才可设置级别，默认三级用户)</td>
        </tr>
        <!--{/if}-->
    </table>
</div>
<div class="page_table form_table" id="tab2">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      
        <tr>
          <td width="100" align="right">内容访问权限
          <br />
			</td>
          <td colspan="2">
            <ul id="tree" class="ztree">
            </ul>
          </td>
        </tr>
        
    </table>
</div>
<div class="page_table form_table" id="tab3">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="100" align="right">主菜单访问权限</td>
          <td colspan="2">
          <fieldset class="source">
          <legend>选择权限</legend>
              <!--foreach:{$menu_list $vo}-->
              <input name="menu_power[]" type="checkbox" value="{$vo['id']}"  <!--if:{!empty($menu_power)&&in_array($vo['id'],$menu_power)}--> checked="checked" <!--{/if}-->  /> {$vo.name}&nbsp;&nbsp;
              <!--{/foreach}-->
          </fieldset>
          </td>
        </tr>
        <!--foreach:{$menu_list $vo}-->
        <tr>
          <td width="100" align="right">{$vo.name}操作权限</td>
          <td colspan="2">
          <?php $list=model('menu')->menu_list($vo['id']); if(!empty($list)) foreach($list as $vo){?>
          <fieldset class="source">
          <legend><input class="sub" name="model_power[{$vo['id']}][]" type="checkbox" value="{$vo['id']}" <!--if:{!empty($model_power)&&in_array($vo['id'],(array)$model_power[$vo['id']])}--> checked="checked" <!--{/if}--> > {$vo['name']}</legend>
          <?php $list=model('user_group')->admin_power($vo['id']); if(!empty($list)) foreach($list as $val){?>
              <input class="sub" name="model_power[{$vo['id']}][]" type="checkbox" value="{$val['action']}"  <!--if:{!empty($model_power)&&in_array($val['action'],(array)$model_power[$vo['id']])}--> checked="checked" <!--{/if}-->  /> {$val.name}&nbsp;&nbsp;
          <?php } ?> 
          </fieldset>
          <?php } ?>
          </td>
        </tr>  
        <!--{/foreach}-->
        <tr>
          <td width="100" align="right">表单管理权限</td>
          <td colspan="2">
          <!--foreach:{$form_list $vo}-->
           <fieldset class="source">
              <legend><input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="{$vo['id']}" <!--if:{!empty($form_power)&&in_array($vo['id'],(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}--> > {$vo['name']}</legend>
              
              <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="visit"  <!--if:{!empty($form_power)&&in_array('visit',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}-->  /> 浏览&nbsp;&nbsp;
              <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="add"  <!--if:{!empty($form_power)&&in_array('add',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}-->  /> 添加&nbsp;&nbsp;
              <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="edit"  <!--if:{!empty($form_power)&&in_array('edit',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}-->  /> 编辑&nbsp;&nbsp;
              <input class="sub" name="form_power[{$vo['id']}][]" type="checkbox" value="del"  <!--if:{!empty($form_power)&&in_array('del',(array)$form_power[$vo['id']])}--> checked="checked" <!--{/if}-->  /> 删除&nbsp;&nbsp;
               
          </fieldset>
          <!--{/foreach}-->
          </td>
        </tr>
    </table>
</div>
<?php if(model('user_group')->model_power('user_group','add')||model('user_group')->model_power('user_group','edit')){ ?>
<!--普通提交-->
<div class="form_submit">
<input name="id" type="hidden" value="{$info.id}" />
<input name="class_power" id="class_power" type="hidden" value="" />
<button type="submit" class="button">保存</button> 
</div>
<?php } ?>
</form>
</div>
</div>
<script type="text/javascript">
//tab菜单
$("#tab").idTabs();
$('.source input').click(function() {
	var num=0;
	$(this).parent().find(".sub").each(function(){
		if($(this).attr("checked")){
			num=num+1;
    	}
    })
	if(num>0){
		$(this).parent().find("legend input").removeAttr('checked');
	}
});
//提交表单
savelistform({addurl:"__URL__/add",listurl:"__URL__",
data:function(){
	var zTree = $.fn.zTree.getZTreeObj("tree");
	var nodes = zTree.getCheckedNodes(true);
	var purview = "";
	for (var i = 0; i < nodes.length; i++) {
    	purview +=  nodes[i].cid+",";
    }
	$('#class_power').val(purview);
}
});
</script>